<?php

autoLoader();

$objWardTypes 	= new WardTypes();
$arrobjWardTypes 	= $objWardTypes->fetchAllWardTypes();

$arrobjWardCatagories = new WardCatagories();
$arrobjWardCatagories = $arrobjWardCatagories->fetchAllWardCatagories();
$arrobjWardCatagories = rekeyObjects( 'Id', $arrobjWardCatagories );

if( false == valArr( $arrobjWardTypes ) ) {
	echo '<h2>Ward Types are not avaliable.</h2>';
} else {
?>
<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="js/bootstrap-confirmation.js" type="text/javascript"></script>
<script>
	$(document).ready(function() {
		$('#dataTables-example').dataTable();
	});
</script>
<script>
function DeleteData(id){
	var r = confirm( "Are You Sure Delete This Ward Type?" );
	if( r == true ) {
		$.ajax({
			type: "POST",
			url: "modules.php?file=delete_wards_type",
			data:{did:id},
			beforeSend : function () {
			},
			success:function(){
				location.reload();
			}
		});
	}
}
</script>
<style>
	.thclass{
	font-size:12px;
	}
	.tbclass{
	font-size:12px;
	}
</style>
<div style="margin-left:12px; margin-top: 10px;">
	<p>
		<a class="btn btn-outline btn-primary btn-xs" id="act" href="modules.php?file=wards_type&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Add New Ward Type</a>
		<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_wards_type&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Ward Types</a>&nbsp;
	</p>
</div>
<div class="col-lg-12">
	<div class="panel panel-primary">
		
		<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>WardType List</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="dataTables-example">
					<thead class="thclass">
						<tr>
							<th>Sr.No</th>
							<th>Id</th>
							<th>Name</th>
							<th>Description</th>
							<th>Ward Catagory</th>
							<th>Is Published</th>
							<th>Edit</th>
							<th>Delete</th>
					</thead>
					<tbody class="tbclass">
					<?php 
					$intSnCount = 1;
					foreach( $arrobjWardTypes as $objWardType ) {
					?>
						<tr class="odd gradeX">
							<td><?  echo $intSnCount; ?></td>
							<td><? echo $objWardType->getId(); ?></td>
							<td><? echo $objWardType->getName(); ?></td>
							<td><? echo $objWardType->getDescription(); ?></td>
							<td><?php $objWardCatagory = getArrayElementByKey( $objWardType->getWardCatagoryId(), $arrobjWardCatagories ); echo ( true == valObj( $objWardCatagory, 'BaseWardCatagories' ) ) ? $objWardCatagory->getName() : NULL; ?>
							<td><? echo $objWardType->getIsPublished(); ?></td>
							<td>
								<a href="modules.php?file=wards_type&ward_type_id=<? echo $objWardType->getId(); ?>&mid=<? echo $mid;?>&smid=<? echo $smid;?>"><img src="images/icons/update.png" width="25" height="25"></a>
							</td>
							<td>
								<a id="delete_wards_type" onClick="DeleteData(<?echo $objWardType->getId();?>);"><img src="images/icons/delete.jpg" width="25" height="25"></a>
							</td>
						</tr>
					<?
					} 
					?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<?php
}
?>